package com.wonderful.map.view

import android.content.Context
import android.graphics.Paint
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.wonderful.map.R
import com.wonderful.map.constant.MapConstant

/**
 * Desc: 虚拟障碍物 view，如：虚拟器、斜坡、门禁等
 * @Author: wonderful
 * @Time: 2023/5/30 15:57
 */
class VirtualObstacleView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    defStyleRes: Int = 0
) : BaseVirtualView(context, attrs, defStyleAttr, defStyleRes) {

    private val colorMarkSlope = ContextCompat.getColor(context, R.color.color_mark_slope)
    private val colorSpeedBumps = ContextCompat.getColor(context, R.color.color_speed_bumps)
    private val colorBlowArea = ContextCompat.getColor(context, R.color.color_blow_area)
    private val colorDoorAccess = ContextCompat.getColor(context, R.color.color_door_access)
    private val colorBeautify = ContextCompat.getColor(context, R.color.color_beautify)

    /**
     * 更新画笔样式
     */
    override fun updatePaintStyle(isClicked: Boolean, type: Int) {
        if (isClicked) {
            mPolylinePaint.color = colorClicked
            mPolygonPaint.color = colorClicked
            mCirclePaint.color = colorClicked
            return
        }
        when (type) {
            MapConstant.EditType.MARK_SLOPE -> {
                mPolylinePaint.color = colorMarkSlope
                mPolygonPaint.apply {
                    color = colorMarkSlope
                    style = Paint.Style.STROKE
                }
                mCirclePaint.color = colorMarkSlope
            }

            MapConstant.EditType.SPEED_BUMPS -> {
                mPolylinePaint.color = colorSpeedBumps
                mPolygonPaint.apply {
                    color = colorSpeedBumps
                    style = Paint.Style.STROKE
                }
                mCirclePaint.color = colorSpeedBumps
            }

            MapConstant.EditType.BLOW_AREA -> {
                mPolylinePaint.color = colorBlowArea
                mPolygonPaint.apply {
                    color = colorBlowArea
                    style = Paint.Style.STROKE
                }
                mCirclePaint.color = colorBlowArea
            }

            MapConstant.EditType.DOOR_ACCESS -> {
                mPolylinePaint.color = colorDoorAccess
                mPolygonPaint.apply {
                    color = colorDoorAccess
                    style = Paint.Style.FILL
                }
                mCirclePaint.color = colorDoorAccess
            }

            MapConstant.EditType.RAW_MAP_CLEAR,
            MapConstant.EditType.RAW_MAP_FILL -> {
                mPolylinePaint.color = colorBeautify
                mPolygonPaint.apply {
                    color = colorBeautify
                    style = Paint.Style.FILL
                }
                mCirclePaint.color = colorBeautify
            }

            else -> {
                mPolylinePaint.color = colorDefault
                mPolygonPaint.apply {
                    color = colorDefault
                    style = Paint.Style.STROKE
                }
                mCirclePaint.color = colorDefault
            }
        }
    }

}